<?php

/**
 * @package Skjb_Library
 */

/**
 * MPlayer Tool
 *
 * @package Skjb_Library
 */
class Skjb_Video_Mplayer
{
    public $path = null;
    
    public function __construct($path)
    {
        $this->path = $path;
    }
    
    public function identify($file)
    {
        $command = $this->path;
        $command .= ' -frames 0';
        $command .= ' -identify';
        $command .= ' ' . $file;
        $result = shell_exec($command);

        $video = new stdClass();

        if (!preg_match('/ID_VIDEO_WIDTH=(\d+)/', $result, $matches)) {
            throw new Zend_Exception('Unable to get width');
        }
        $video->width = $matches[1];
        
        if (!preg_match('/ID_VIDEO_HEIGHT=(\d+)/', $result, $matches)) {
            throw new Zend_Exception('Unable to get height');
        }
        $video->height = $matches[1];
        
        if (!preg_match('/ID_VIDEO_FPS=([0-9\.]+)/', $result, $matches)) {
            throw new Zend_Exception('Unable to get frames per second');
        }
        $video->fps = $matches[1];
        
        if (!preg_match('/ID_LENGTH=([0-9\.]+)/', $result, $matches)) {
            throw new Zend_Exception('Unable to get duration');
        }
        $video->seconds = $matches[1];
        
        return $video;
    }
}